﻿using IcsSEMCtrl.Device.Observe;
using IcsSEMCtrl.Global.Device;
using TKT.Lifter.CIM.Lifter.Event.Lifter;

namespace Lifter.Device.Unit
{
    public class EFUFan : LocationUnit
    {
        public int tempSpeed = 0;
        public override void Init()
        {
            base.Init();
            this.AddSubscribe();
        }
        public void AddSubscribe()
        {
            this._I_EFU01SPEEDCHANGERPY.ObservableValueChanged += new DelegateObservableValueChanged(_I_EFU01SPEEDCHANGERPY_ObservableValueChanged);
            this._I_EFU01SPEEDCHANGERPT.ObservableValueChanged += new DelegateObservableValueChanged(_I_EFU01SPEEDCHANGERPT_ObservableValueChanged);
        }

        private void _I_EFU01SPEEDCHANGERPT_ObservableValueChanged(object sender, object value)
        {
            short efuSpeedValue = this.I_EFU01SPEEDCHANGERPTDATA;
            Observable obj = (Observable)sender;
            //推送风扇转速
            base.PublishEvent(FanSenderEvent.FormSubject("Fan"), new FanSenderEvent(this.elementId, EquipmentType.ValueToString(EquipmentType.LIFTER), obj.OwnerId, efuSpeedValue, false));
        }

        private void _I_EFU01SPEEDCHANGERPY_ObservableValueChanged(object sender, object value)
        {
            if ((bool)value)
            {
                this.O_EFU01SPEEDCHANGEREQ = false;
                short efuSpeedValue = (short)this.tempSpeed;
                Observable obj = (Observable)sender;
                //推送风扇转速
                base.PublishEvent(FanSenderEvent.FormSubject("Fan"), new FanSenderEvent(this.elementId, EquipmentType.ValueToString(EquipmentType.LIFTER), obj.OwnerId, efuSpeedValue, false));
            }
        }

        public Observable _I_EFU01SPEEDCHANGERPY
        {
            get
            {
                return base.Observables["EFU01SPEEDCHANGERPY"];
            }
        }
        public Observable _I_EFU01SPEEDCHANGERPT
        {
            get
            {
                return base.Observables["EFU01SPEEDCHANGERPT"];
            }
        }
        public short O_EFU01SPEEDCHANGEREQDATA
        {
            set
            {
                base.observables["EFU01SPEEDCHANGEREQDATA"].AsShort = value;
            }
        }
        public short I_EFU01SPEEDCHANGERPTDATA
        {
            get
            {
                return base.observables["EFU01SPEEDCHANGERPTDATA"].AsShort;
            }
        }

        public bool O_EFU01SPEEDCHANGEREQ
        {
            set
            {
                base.observables["EFU01SPEEDCHANGEREQ"].AsBoolean = value;
            }
        }

        private void _I_FANState_ObservableValueChanged(object sender, object value)
        {
            Observable obj = (Observable)sender;
            bool Status = (bool)value;
            //推送风扇状态
            base.PublishEvent(FanSenderEvent.FormSubject("Fan"), new FanSenderEvent(this.elementId, EquipmentType.ValueToString(EquipmentType.LIFTER), obj.OwnerId, Status, true));
        }
    }
}
